// src/stores/auth.js
import { defineStore } from 'pinia'

export const useAuthStore = defineStore('auth', {
state: () => ({
user: null,
isAuthenticated: false
}),
actions: {
async login(credentials) {
// 这里实现你的登录逻辑
const { email, password } = credentials
if (!email || !password) {
throw new Error('邮箱和密码不能为空');
}
// 模拟登录
return new Promise((resolve) => {
setTimeout(() => {
this.user = { email }
this.isAuthenticated = true
resolve()
}, 1000)
})
},
logout() {
this.user = null
this.isAuthenticated = false
}
}
})